//
//  HMStatusRetweetView.m
//  SinaWeiBo
//
//  Created by WGP on 16/4/16.
//  Copyright © 2016年 WGP. All rights reserved.
//

#import "HMStatusRetweetView.h"
#import "HMStatusPictureView.h"
#import "HMStatuses.h"

@interface HMStatusRetweetView ()

@property(nonatomic,strong)UIButton *bgButton;
@property(nonatomic,strong)UILabel *contentLabel;
@property(nonatomic,strong)HMStatusPictureView *pictureView;

@end

@implementation HMStatusRetweetView

-(instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame])
    {
        [self setupUI];
    }
    return  self;
}

-(instancetype)initWithCoder:(NSCoder *)aDecoder
{
    if(self = [super initWithCoder:aDecoder])
    {
        [self setupUI];
    }
    return self;
}


-(void)setupUI
{
//    1.添加子控件
    self.bgButton = [[UIButton alloc] init];
    [self.bgButton setBackgroundImage:[UIImage imageNamed:@"retweet_background_highlighted"] forState:UIControlStateHighlighted];
    [self.bgButton setBackgroundImage:[UIImage imageNamed:@"retweet_background"] forState:UIControlStateNormal];
    [self addSubview:self.bgButton];
    
    self.contentLabel = [[UILabel alloc] init];
    self.contentLabel.font = [UIFont systemFontOfSize:HMContentLabelFontSize];
    self.contentLabel.textColor = [UIColor darkGrayColor];
    self.contentLabel.numberOfLines = 0;
    [self addSubview:self.contentLabel];
    
    self.pictureView = [[HMStatusPictureView alloc] init];
    [self addSubview:self.pictureView];
    
//    2.添加约束
    [self.bgButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self);
    }];
    
    [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.equalTo(self).offset(HMStatusCellMargin);
        make.right.equalTo(self).offset(-HMStatusCellMargin);
    }];
    
    [self.pictureView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(HMStatusCellMargin);
        make.top.equalTo(self.contentLabel.mas_bottom).offset(HMStatusCellMargin);
        make.size.mas_equalTo(CGSizeZero);
    }];
    
    [self mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.pictureView.mas_bottom).offset(HMStatusCellMargin);
    }];
}

-(void)setStatus:(HMStatuses *)status
{
    _status = status;
    
    NSString *content = [NSString stringWithFormat:@"@%@:%@",status.user.screen_name,status.text];
    self.contentLabel.text = content;
    
    self.pictureView.pic_urlsArr = status.pic_urlsArr;
    
    [self.pictureView mas_updateConstraints:^(MASConstraintMaker *make) {
        CGFloat margin = status.pic_urlsArr.count == 0 ? 0 : HMStatusCellMargin;
        make.top.equalTo(self.contentLabel.mas_bottom).offset(margin);
    }];
}

@end










